<html>
<head><meta charset="utf-8"><title>Capture-disjoint-fields and Clone · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html">Capture-disjoint-fields and Clone</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216698416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216698416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216698416">(Nov 14 2020 at 01:59)</a>:</h4>
<p>The conversation about <code>Default</code> closures had me thinking about <code>Clone</code> closures.</p>
<p>Will <a href="https://github.com/rust-lang/rfcs/issues/2229">RFC#2229</a> technically be a breaking change because of that?  It seems possible, if uncommon, for a <code>move</code> closure to currently be <code>Clone</code> because it captured the whole instance, but that capturing subfields could capture things that are not themselves <code>Clone</code>, and thus make the closure no longer <code>Clone</code>.  (Maybe one of the fields cannot be safely copied, but the captured things wraps it up into something that can always do so soundly.)</p>
<p>(That can't be a problem with <code>Copy</code>, since all subfields have to be <code>Copy</code> anyway.  So it'll just make more closures <code>Copy</code> than used to be.)</p>



<a name="216700119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216700119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216700119">(Nov 14 2020 at 02:38)</a>:</h4>
<p>I do think Clone for non-Copy closures, in hindsight, may have been a mistake given the new insights from the Default conversation.</p>



<a name="216700527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216700527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216700527">(Nov 14 2020 at 02:45)</a>:</h4>
<p>Good point. The way I understand the trait selection code only cares about the types that are being captured, so yeah it might break. Though I'm _assuming_ such time would probably need custom drop too.</p>
<p>2229 also breaks drop order, so the migration tool/lint that we will provide should be able to handle this as well.  Post-migration the closure will essentially be capturing the entire structure as it did before.</p>



<a name="216948078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216948078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216948078">(Nov 16 2020 at 23:35)</a>:</h4>
<p>Also <span class="user-mention" data-user-id="116009">@nikomatsakis</span>  in acse you haven't seen this. You probably understand the implication here better than I do.</p>



<a name="216948219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216948219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216948219">(Nov 16 2020 at 23:36)</a>:</h4>
<p>Yeah, that's a good catch. We can work-around this if necessary.</p>



<a name="216948233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216948233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216948233">(Nov 16 2020 at 23:37)</a>:</h4>
<p>But we should open an issue to track it.</p>



<a name="216948263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216948263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216948263">(Nov 16 2020 at 23:37)</a>:</h4>
<p>(we could insert a <code>let a = a</code> statement if the thing being captured is not clone, but the original is)</p>



<a name="216948345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/216948345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#216948345">(Nov 16 2020 at 23:38)</a>:</h4>
<p>Yeah that's what I was thinking, not sure if we want to proactively do that or let the user apply the migration lint themselves</p>



<a name="217027238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Capture-disjoint-fields%20and%20Clone/near/217027238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Capture-disjoint-fields.20and.20Clone.html#217027238">(Nov 17 2020 at 16:34)</a>:</h4>
<p>This is something I've been deferring, but we're going to need the lint anyway, and I am imagining it's going to have some heuristics</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>